// 导出组件
export { default as Example } from './comp'

// 导出描述 
export const description = `useReducer flux数据解决方案的一个实现方式`

// 导出组件代码文本
export const compstr = `
import React, { useReducer } from 'react'

// 通过reducer 改变数据
function reducer(state, payload) {
  switch (payload.type) {
    case 'add':
      return state + 1
    case 'del':
      return state - 1
    default:
      return state
  }
}

const initVal = 1
export default function Comp() {
  const [n, dispatch] = useReducer(reducer, initVal)
  return (
    <>
      <div>n: {n}</div>
      <button onClick={() => dispatch({ type: 'add' })} style={{marginRight:10}}>n+1</button>
      <button onClick={() => dispatch({ type: 'del' })}>n-1</button>
    </>
  )
}
`